summaryrefslogtreecommitdiff
path: root/src/container.h
blob: f341bf893d90888c1bd5b78be603e653cabe58ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef NEURAL_CONTAINER_H
#define NEURAL_CONTAINER_H

#include "neural/node.h"
#include <bu/list.h>

namespace Neural
{
	template<typename sigtype>
	class Container : public Node<sigtype>
	{
	public:
		typedef Bu::List<Neural::Node<sigtype> *> NodeList;

		Container()
		{
		}

		virtual ~Container()
		{
			for( typename NodeList::iterator i = lNodes.begin(); i; i++ )
				delete *i;
		}

		virtual int setWeights( const sigtype *pWeights )
		{
			int iOffset = 0;
			for( typename Container<sigtype>::NodeList::iterator i =
				Container<sigtype>::getNodeList().begin(); i; i++ )
			{
				iOffset += (*i)->setWeights( &pWeights[iOffset] );
			}

			return iOffset;
		}

		virtual int setBiases( const sigtype *pBiases )
		{
			int iOffset = 0;
			for( typename Container<sigtype>::NodeList::iterator i =
				Container<sigtype>::getNodeList().begin(); i; i++ )
			{
				iOffset += (*i)->setBiases( &pBiases[iOffset] );
			}

			return iOffset;
		}

		virtual void addNode( Node<sigtype> *pNode )
		{
			lNodes.append( pNode );
		}

		virtual const NodeList &getNodeList() const
		{
			return lNodes;
		}

	protected:
		virtual NodeList &getNodeList()
		{
			return lNodes;
		}

	private:
		NodeList lNodes;
	};
};

#endif